#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""
"""



class Solution:
    """
    @param strs: A list of strings
    @return: The longest common prefix
    """
    def longestCommonPrefix(self, strs):
        if not strs:
            return ""

        cnt = 0
        min_len = min( map(len, strs) )
        self.l = len(strs)
        self.strs = strs

        for i in range(min_len):
            if not self.equal(i):
                break
            cnt += 1

        return strs[0][:cnt]

    def equal(self, i):
        v = self.strs[0][i]

        for si in range(1, self.l):
            if self.strs[si][i] != v:
                return False

        return True


def main():
    print("start main")
    s = Solution()
    ret = s.longestCommonPrefix(["ABCDEFG", "ABCEFG", "ABCEFA"])
    print(ret)

if __name__ == "__main__":
    main()
